<div class="main-content">
	<div class="breadcrumbs" id="breadcrumbs">
		<ul class="breadcrumb">
			<li>
				<i class="icon-home home-icon"></i>
				<a href="#">系统首页</a>
			</li>
			<li class="active">
				基础数据管理
			</li>
            <li>
				<a href="#">行业类别</a>
			</li>
            <li class="active">
				编辑
			</li>
		</ul><!-- .breadcrumb -->
	</div>
	<div class="page-content">
	    <div class="page-header">
			<h1>编辑行业类别</h1>
		</div>
		<div class="row">
			 <div class="col-xs-12">
				<!-- PAGE CONTENT BEGINS -->

				<form id="usrform" action="<?php echo base_url()."admin/basis_data/edit_work_type/";?>" method="post">
				<input name="id" type="hidden" value="<?php if (isset($work_val[0]->id))echo $work_val[0]->id;?>">
				<input name="parent_id" type="hidden" value="<?php if (isset($work_val[0]->parent_id))echo $work_val[0]->parent_id;?>">
				    <div class="box-body" style="display: inline-block;width: 100%">
				        <div class="form-group col-xs-6">
				            <label>行业名称</label><span style="color: #a94442;"><?php echo form_error("work_name")?></span>
				            <input name="work_name" type="text" class="form-control" placeholder="输入 ..." value="<?php if (validation_errors()!='')echo set_value('work_name');elseif (isset($work_val[0]->work_name))echo $work_val[0]->work_name;?>" check-type="required">
			            </div>
			            <div class="form-group col-xs-6">
		                    <label>上级行业</label>
				                <select name="work_id" class="form-control">
				                    <option value="">请选择</option>
				                    <?php if (isset($work_type)){
				                        foreach ($work_type as $val){?>
				                            <option value="<?php echo $val->id;?>" <?php if (isset($work_val[0]->parent_id)&&$work_val[0]->parent_id == $val->id)echo 'selected';?>><?php echo $val->work_name;?></option>
				                        <?php }
				                    }?>
				                </select>
		                </div>
                        </div>
			            <div class="clearfix form-actions">
						<div class="col-md-offset-3 col-md-9">
							<button id="btnSubmit" class="btn btn-info" type="submit">
								<i class="icon-ok bigger-110"></i>
								保存
							</button>

							&nbsp; &nbsp; &nbsp;
							<a class="btn" href="<?php echo base_url()."admin/basis_data/work_type"?>">
								<i class="icon-undo bigger-110"></i>
								返回
							</a>
						</div>
					</div>
				</form>
			</div>
		</div><!-- /.row -->
	</div><!-- /.page-content -->
</div><!-- /.main-content -->
<script type="text/javascript">
	$("#usrform").validation();
	//保存
	$("#btnSubmit").on('click',function(event){
	  // 2.最后要调用 valid()方法。
	  if ($("#usrform").valid()==false){
	    return false;
	  }
	});
	function _init_type(category_id,type_id,select_category_id,select_type_id,base_url){
		$('#'+category_id).change(function(){
			type_option(category_id,type_id,select_type_id,base_url);
		});
		$.ajax( {
	        url:base_url+'api/common/category',
	        data:{},
	        type:'post',
	        cache:false,
	        dataType:'json',    
	        success:function(data) {
	        	var category = document.getElementById(category_id);
	        	category.options.length = 1;
	        	for(var i=0; i<data.category.length; i++)
				{
	        		var len = category.length;
	        		category.options[len] = new Option(data.category[i].name, data.category[i].id);
					if (category.options[len].value == select_category_id)
					{
						category.options[len].selected = true;
					}
				}
	        	type_option(category_id,type_id,select_type_id,base_url);
	        },
	        error : function() {       
	            alert("error");
	        }
		});
	}
	function type_option(category_id,type_id,select_type_id,base_url){
		$.ajax( {
	        url:base_url+'api/common/type',
	        data:{category_id:$('#'+category_id).val()},
	        type:'post',
	        cache:false,
	        dataType:'json',    
	        success:function(data) {
	        	var type = document.getElementById(type_id);
	        	type.options.length = 1;
	        	for(var i=0; i<data.type.length; i++)
				{
	        		var len = type.length;
	        		type.options[len] = new Option(data.type[i].name, data.type[i].id);
					if (type.options[len].value == select_type_id)
					{
						type.options[len].selected = true;
					}
				}
	        	
	        },
	        error : function() {       
	            alert("error");
	        }
		});
	}
</script>